package com.li.drug.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.li.drug.entity.Owinfo;
import com.li.drug.mapper.OwinfoMapper;
import com.li.drug.service.OwinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thymeleaf.util.StringUtils;

/**
 * 药品出入库service实现类
 */
@Service
public class OwinfoServiceImpl extends ServiceImpl<OwinfoMapper, Owinfo> implements OwinfoService {

    @Autowired
    OwinfoMapper owinfoMapper;

    /**
     * 分页查询药品出入库数据
     * @param pageNum 第几页
     * @param pageSize 每页多少条数据
     * @param param 查询参数 - 药品名称
     * @return
     */
    @Override
    public Page<Owinfo> selectOwinfoPage(int pageNum, int pageSize, String param) {
        //构建查询条件
        QueryWrapper<Owinfo> wrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(param)){
            wrapper.like("dname",param);
        }
        //构建分页查询对象
        Page<Owinfo> page = new Page<>(pageNum,pageSize);
        return owinfoMapper.selectPage(page,wrapper);
    }

    @Override
    public int addOwinfo(Owinfo owinfo) {
        return owinfoMapper.insert(owinfo);
    }

    @Override
    public int editOwinfo(Owinfo owinfo) {
        return owinfoMapper.updateById(owinfo);
    }

    @Override
    public Owinfo getOwinfoById(Integer id) {
        return owinfoMapper.selectById(id);
    }

    @Override
    public int delOwinfoById(Integer id) {
        return owinfoMapper.deleteById(id);
    }
}
